"""ADC model based on data taken from a spreadsheet of recorded data.

Copyright (C) Sarah Mount, 2008.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
"""

from __future__ import absolute_import
del absolute_import
from .. import ADCModel

class ADCCSVModel(ADCModel.ADCModel, object):
    """ADC model which returns data read from a CSV file on disk.

    Useful for driving a simulation with 'real' data.

    TODO: This is largely a placeholder for now. There is one major
    issue which is that all sensors should share a reference to this
    ADC model, rather than each having its own instance. This class
    should conform to the singleton pattern. It may be simpler to only
    allow sensors to register interest in a stream of corresponding to
    some primary key in the spreadsheet, rather than getting point
    data.
    """
    __instance = None       
    def __new__(cls, *args, **kargs): 
        """Create a new instance of this class, ensuring conformance
        to the singleton pattern.

        See U{http://en.wikipedia.org/wiki/Singleton_pattern#Python}
        """
        if cls.__instance is None:
            cls.__instance = object.__new__(cls, *args, **kargs)
        return cls.__instance
    def __init__(self, filename=None):
        """
	@precondition: C{filename} must exist on disk and be a CSV file
        @type filename: str
        @param filename: full path to CSV file on disk
        """
        ADCModel.ADCModel.__init__(self)
        self.name = 'From Spreadsheet'        
        self.csvfile = filename
        return
    def getPointData(self, vector=1, transducer=None):
        """TODO: Writeme!
        """
        return (None, None)


adcCSVModel = ADCCSVModel()

# if __name__ == '__main__':
#     print 'Checking conformance to Singleton pattern...'
#     models = [ADCCSVModel() for i in range(10)]

#     for model in models:
#         assert model is models[0]
#         print model
